import 'dart:convert';
import 'package:ichinesereader/models/book/BookLevel.dart';
import 'package:ichinesereader/models/common/Settings.dart';
import 'package:ichinesereader/models/student/StudentItem.dart';

ClassDetailsNew classDetailsNewFromJson(String str) =>
    ClassDetailsNew.fromJson(json.decode(str));

String classDetailsNewToJson(ClassDetailsNew data) =>
    json.encode(data.toJson());

class ClassDetailsNew {
  ClassDetailsNew({
    this.classCode,
    this.classId,
    this.classLevel,
    this.className,
    this.createDate,
    this.gameDisable,
    this.level,
    this.numBooks,
    this.numOfAssignment,
    this.numQuizzes,
    this.program,
    this.settings,
    this.shelf,
    this.studentResps,
    this.teacherResps,
    this.viewReport,
  });

  String? classCode;
  String? classId;
  Level? classLevel;
  String? className;
  int? createDate;
  bool? gameDisable;
  String? level;
  int? numBooks;
  int? numOfAssignment;
  int? numQuizzes;
  Program? program;
  Settings? settings;
  String? shelf;
  //List<StudentResp>? studentResps;
  List<StudentItem>? studentResps;
  List<TeacherResp>? teacherResps;
  bool? viewReport;

  factory ClassDetailsNew.fromJson(Map<String, dynamic> json) =>
      ClassDetailsNew(
        classCode: json["classCode"],
        classId: json["classId"],
        classLevel: json["classLevel"] != null
            ? Level.fromJson(json["classLevel"])
            : null,
        className: json["className"],
        createDate: json["createDate"],
        gameDisable: json["gameDisable"],
        level: json["level"],
        numBooks: json["numBooks"],
        numOfAssignment: json["numOfAssignment"],
        numQuizzes: json["numQuizzes"],
        program:
            json["program"] != null ? Program.fromJson(json["program"]) : null,
        settings: json["settings"] != null
            ? Settings.fromJson(json["settings"])
            : null,
        shelf: json["shelf"],
        studentResps: json["studentResps"] != null
            ? List<StudentItem>.from(
                json["studentResps"].map((x) => StudentItem.fromJson(x)))
            : null,
        teacherResps: json["teacherResps"] != null
            ? List<TeacherResp>.from(
                json["teacherResps"].map((x) => TeacherResp.fromJson(x)))
            : null,
        viewReport: json["viewReport"],
      );

  Map<String, dynamic> toJson() => {
        "classCode": classCode,
        "classId": classId,
        "classLevel": classLevel?.toJson(),
        "className": className,
        "createDate": createDate,
        "gameDisable": gameDisable,
        "level": level,
        "numBooks": numBooks,
        "numOfAssignment": numOfAssignment,
        "numQuizzes": numQuizzes,
        "program": program?.toJson(),
        "settings": settings?.toJson(),
        "shelf": shelf,
        "studentResps": studentResps != null
            ? List<dynamic>.from(studentResps!.map((x) => x.toJson()))
            : null,
        "teacherResps": teacherResps != null
            ? List<dynamic>.from(teacherResps!.map((x) => x.toJson()))
            : null,
        "viewReport": viewReport,
      };
}

class Program {
  Program({
    this.name,
    this.tree,
    this.id,
  });

  String? name;
  Tree? tree;
  String? id;

  factory Program.fromJson(Map<String, dynamic> json) => Program(
        name: json["name"],
        tree: json["tree"] != null ? Tree.fromJson(json["tree"]) : null,
        id: json["id"],
      );

  Map<String, dynamic> toJson() => {
        "name": name,
        "tree": tree?.toJson(),
        "id": id,
      };
}

class Tree {
  Tree({
    this.name,
    this.id,
    this.lowerProgram,
  });

  String? name;
  String? id;
  List<Tree>? lowerProgram;

  factory Tree.fromJson(Map<String, dynamic> json) => Tree(
        name: json["name"],
        id: json["id"],
        lowerProgram: json["lowerProgram"] != null
            ? List<Tree>.from(json["lowerProgram"].map((x) => Tree.fromJson(x)))
            : null,
      );

  Map<String, dynamic> toJson() => {
        "name": name,
        "id": id,
        "lowerProgram": lowerProgram != null
            ? List<dynamic>.from(lowerProgram!.map((x) => x.toJson()))
            : null,
      };
}

class StudentResp {
  StudentResp({
    this.accessCode,
    this.classNames,
    this.dateOfBirth,
    this.deleted,
    this.disabled,
    this.email,
    this.excludeFromLeaderboard,
    this.firstName,
    this.gameDisable,
    this.gender,
    this.id,
    this.lastLoggedIn,
    this.lastName,
    this.level,
    this.levelPercentage,
    this.nickName,
    this.numBooks,
    this.numQuizzes,
    this.parentEmail,
    this.playerLevel,
    this.points,
    this.settings,
    this.timestampCreated,
    this.totalGameTime,
    this.totalLoginTime,
    this.userId,
    this.userName,
  });

  String? accessCode;
  String? classNames;
  String? dateOfBirth;
  bool? deleted;
  bool? disabled;
  String? email;
  bool? excludeFromLeaderboard;
  String? firstName;
  bool? gameDisable;
  String? gender;
  String? id;
  int? lastLoggedIn;
  String? lastName;
  String? level;
  int? levelPercentage;
  String? nickName;
  int? numBooks;
  int? numQuizzes;
  String? parentEmail;
  Level? playerLevel;
  int? points;
  Settings? settings;
  int? timestampCreated;
  int? totalGameTime;
  int? totalLoginTime;
  String? userId;
  String? userName;

  factory StudentResp.fromJson(Map<String, dynamic> json) => StudentResp(
        accessCode: json["accessCode"],
        classNames: json["classNames"],
        dateOfBirth: json["dateOfBirth"],
        deleted: json["deleted"],
        disabled: json["disabled"],
        email: json["email"],
        excludeFromLeaderboard: json["excludeFromLeaderboard"],
        firstName: json["firstName"],
        gameDisable: json["gameDisable"],
        gender: json["gender"],
        id: json["id"],
        lastLoggedIn: json["lastLoggedIn"],
        lastName: json["lastName"],
        level: json["level"],
        levelPercentage: json["levelPercentage"],
        nickName: json["nickName"],
        numBooks: json["numBooks"],
        numQuizzes: json["numQuizzes"],
        parentEmail: json["parentEmail"],
        playerLevel: json["playerLevel"] != null
            ? Level.fromJson(json["playerLevel"])
            : null,
        points: json["points"],
        settings: json["settings"] != null
            ? Settings.fromJson(json["settings"])
            : null,
        timestampCreated: json["timestampCreated"],
        totalGameTime: json["totalGameTime"],
        totalLoginTime: json["totalLoginTime"],
        userId: json["userId"],
        userName: json["userName"],
      );

  Map<String, dynamic> toJson() => {
        "accessCode": accessCode,
        "classNames": classNames,
        "dateOfBirth": dateOfBirth,
        "deleted": deleted,
        "disabled": disabled,
        "email": email,
        "excludeFromLeaderboard": excludeFromLeaderboard,
        "firstName": firstName,
        "gameDisable": gameDisable,
        "gender": gender,
        "id": id,
        "lastLoggedIn": lastLoggedIn,
        "lastName": lastName,
        "level": level,
        "levelPercentage": levelPercentage,
        "nickName": nickName,
        "numBooks": numBooks,
        "numQuizzes": numQuizzes,
        "parentEmail": parentEmail,
        "playerLevel": playerLevel?.toJson(),
        "points": points,
        "settings": settings != null ? settings?.toJson() : null,
        "timestampCreated": timestampCreated,
        "totalGameTime": totalGameTime,
        "totalLoginTime": totalLoginTime,
        "userId": userId,
        "userName": userName,
      };
}

class TeacherResp {
  TeacherResp({
    this.email,
    this.firstName,
    this.id,
    this.lastName,
    this.userName,
  });

  String? email;
  String? firstName;
  String? id;
  String? lastName;
  String? userName;

  factory TeacherResp.fromJson(Map<String, dynamic> json) => TeacherResp(
        email: json["email"],
        firstName: json["firstName"],
        id: json["id"],
        lastName: json["lastName"],
        userName: json["userName"],
      );

  Map<String, dynamic> toJson() => {
        "email": email,
        "firstName": firstName,
        "id": id,
        "lastName": lastName,
        "userName": userName,
      };
}
